package com.example.wuqujingdianphone.activity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.base.BaseActivity;
import com.example.wuqujingdianphone.fragment.bookcity.BCMultiMediaFragment;
import com.example.wuqujingdianphone.fragment.bookcity.BookCityBookFragment;
import com.example.wuqujingdianphone.fragment.bookcity.TIyanGuanFragment;
import com.example.wuqujingdianphone.fragment.bookcity.TingShuFragment;
import com.example.wuqujingdianphone.fragment.bookcity.WebViewFragment;
import com.example.wuqujingdianphone.view.WebViewActivity3;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MiddleActivity extends BaseActivity {

    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;

    private FragmentManager fm;
    private String channelType = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_middle);
        ButterKnife.bind(this);
        channelType = getIntent().getStringExtra("type");
        mTitle.setText(channelType);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initView();
    }

    private void initView() {
        fm = getSupportFragmentManager();
        switch (channelType) {
            case "不忘初心牢记使命":
                switchFragment(WebViewFragment.getWebViewFragment("不忘初心牢记使命"));
                break;
            case "图书":
                switchFragment(BookCityBookFragment.getBookCityBookFragment());
                break;
            case "音频":
//                switchFragment(BCMultiMediaFragment.getBCMultiMediaFragment("听书馆"));
                switchFragment(TingShuFragment.getTingshuFragment("音频"));
                break;
            case "期刊"://
//                switchFragment(WebViewFragment.getWebViewFragment("期刊"));
                break;
            case "报纸":
//                switchFragment(WebViewFragment.getWebViewFragment("报纸"));
                break;
            case "视频":
//                switchFragment(BCMultiMediaFragment.getBCMultiMediaFragment("体验馆"));
                switchFragment(TIyanGuanFragment.getTIyanGuanFragment("视频"));
                break;
            case "书友会":
                switchFragment(WebViewFragment.getWebViewFragment("书友会"));
                break;
        }
    }

    private void switchFragment(Fragment fragment) {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.content, fragment);
        ft.commit();
    }
}
